package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	agrinet
*/
public class agrinet {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("agrinet.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"agrinet.out")));
		new agrinet().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	private final static int INF = 100001;
	private int 	N;
	private int[] 	dist;
	private int[][] g;
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		N = read(f);
		g = new int[N][N];
		for (int i=0; i<N; i++) {
			for (int count=0; count<N; ) {
				String[] t = f.readLine().split(" ");
				for (String s : t) {
					if (s.length() > 0) {
						g[i][count] = Integer.parseInt(s);
						count++;
					}
				}
			}
		}
		
		dist = new int[N];
		boolean[] include = new boolean[N];
		for (int i=0; i<N; i++) {
			dist[i] = INF;
		}
		update(0);
		include[0] = true;
		int total = 0;
		
		for (int size=1; size<N; size++) {
			int min = -1;
			for (int i=0; i<N; i++) {
				if (!include[i] && 
						(min < 0 || dist[i]<dist[min]) ) min = i;
			}
			
			total += dist[min];
			update(min);
			include[min] = true;
		}
		
		out.println(total);
	}
	
	private void update(int v) {
		for (int i=0; i<N; i++) {
			if (i!=v && dist[i]>g[v][i]) dist[i] = g[v][i];
		}
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
